package zhihuilan.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import zhihuilan.dto.WxMiniPageDto;
import zhihuilan.entity.MyOrderInvoice;
import zhihuilan.entity.MyOrderInvoiceStaff;
import zhihuilan.mapper.MyOrderInvoiceMapper;
import zhihuilan.params.query.MyOrderInvoiceQueryParam;
import zhihuilan.service.MyOrderInvoiceService;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class MyOrderInvoiceServiceImpl extends ServiceImpl<MyOrderInvoiceMapper, MyOrderInvoice> implements MyOrderInvoiceService {


    @Override
    public MyOrderInvoice  selectOrderInvoiceByOrder(String order){
        QueryWrapper<MyOrderInvoice> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("order",order);
        return baseMapper.selectOne(queryWrapper);
    }

    @Override
    public MyOrderInvoice  selectOrderInvoiceByOrderId(Integer orderId){
        QueryWrapper<MyOrderInvoice> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("orderid",orderId);
        return baseMapper.selectOne(queryWrapper);
    }

    @Override
    public  Integer insertOrderInvoice(MyOrderInvoice myOrderInvoice){
       return baseMapper.insert(myOrderInvoice);
    }

    @Override
    public MyOrderInvoice selectOrderInvoiceByIdStatus(Integer id, Integer status){
        QueryWrapper<MyOrderInvoice> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id",id);
        queryWrapper.eq("status",status);
        return baseMapper.selectOne(queryWrapper);
    }

    @Override
    public MyOrderInvoice updateOrderInvoiceByIdStatus(Integer id,Integer status,MyOrderInvoice myOrderInvoice){
        QueryWrapper<MyOrderInvoice> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id",id);
        queryWrapper.eq("status",status);
        Integer i= baseMapper.update(myOrderInvoice,queryWrapper);
        if(i>0){
            return  selectOrderInvoiceByIdStatus( id, 3);
        }
        return null;
    }

    @Override
    public List<MyOrderInvoice>  selectOrderInvoiceList(MyOrderInvoiceQueryParam myOrderInvoiceQueryParam){
        QueryWrapper<MyOrderInvoice> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("staffid",myOrderInvoiceQueryParam.getStaffId());
        queryWrapper.last("limit "+(myOrderInvoiceQueryParam.getPage()-1)* myOrderInvoiceQueryParam.getPageSize()+","+myOrderInvoiceQueryParam.getPageSize());
        return baseMapper.selectList(queryWrapper);

    }
}
